
<%
	//Runtime rt = Runtime.getRuntime();
	/*rt.exec("cmd.exe /c cd \"" + new_dir + "\" & start cmd.exe /k \"java -flag -flag -cp terminal-based-program.jar\"");*/
	//rt.exec("cmd.exe cd \"C:/Program Files/MySQL/MySQL Server 5.5/bin\" mysqldump -uroot -phello htah_database > backup2.sql");
	//Runtime.getRuntime().exec("Cmd /c \"C:/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump\" -uroot -phello htah_database > backup.sql");
	//Runtime.getRuntime().exec("Cmd /c \"mysqldump\" -uroot -phello htah_database > backup.sql");
	// This exports C:\Users\PC\Documents\CSE 305\eclipse-jee-juno-SR1-win32\eclipse. mysqldump.exe is also there

	// Location of mysqldump.exe
	// 	String mysqldump_exe = "mysqldump"; // Currently this is the location of the eclipse IDE.
	// 	String export_location = "backup.sql";
	// 	System.out.println(System.getProperty("user.dir"));

	// 	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	// 	URL resource = classLoader.getResource("mysql/mysqldump.exe");
	// 	File file = new File(resource.getPath());
	// 	System.out.println(file.getPath());

	// 	// Locate mysqldump executable.
	// 	String mysqldump_exe = application.getRealPath("mysql") + "\\" + "mysqldump.exe";
	// 	// Specify output location.
	// 	String output_location = application.getRealPath("mysql") + "\\" + "backup.sql";
	// 	// Export the database.
	// 	Runtime.getRuntime().exec(
	// 			"Cmd /c \"" + mysqldump_exe + "\" -u" + ConnectionInfo.myUserID() + " -p" + ConnectionInfo.myPassword() + " htah_database > "
	// 					+ output_location);
	//	System.out.println("Cmd /c \"" + mysqldump_exe + "\" -u" + ConnectionInfo.myUserID() + " -p" + ConnectionInfo.myPassword() + " htah_database > "
	//				+ output_location);
%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.sql.*" import="Connect.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>Hammer Time Auctions</title>
</head>
<body>
	<div id="content">
		<%@include file="header.jsp"%>
		<h1>Database export successful!</h1>
		<hr></hr>
		<%
// IMPORTANT: Requires mysqldump to be in your eclipse folder!!! /////////////////////////////////////////////////////////////////////////////////////		
		
			//Redirect to the home page if the user is not a manager.
			if (session.getAttribute("user_type") == null) {
				response.sendRedirect("no_permission.jsp");
			} else if (!session.getAttribute("user_type").equals("0")) {
				response.sendRedirect("no_permission.jsp");
			} else {
				out.println("<div class=\"section padding-5px \">");
				Runtime.getRuntime().exec(
						"Cmd /c \"mysqldump\" -u" + ConnectionInfo.myUserID() + " -p" + ConnectionInfo.myPassword() + " htah_database > backup.sql");
				out.println("<b>SQL file exported to:</b> " + System.getProperty("user.dir") + "\\backup.sql<br/>");
				//out.println("<b>SQL file exported to:</b> " + "<a href=\"" + System.getProperty("user.dir") + "/backup.sql\">Download it!</a><br/>");
				//out.println("<a href=\"" + System.getProperty("user.dir") + "\">Download it!</a><br/>");
				out.println("<a href=\"index.jsp\">Click here to return to your dashboard!</a>");
				out.println("</div>");
			}
		%>
	</div>
	<hr></hr>
	<%@include file="footer.jsp"%>
</body>
</html>
